package com.crm.system.service.impl.csd;

import com.alibaba.fastjson.JSONObject;
import com.crm.service.contractManager.CustomerContractDbService;
import com.crm.service.csd.customerManager.ProductExchangeDbService;
import com.crm.service.customerManager.CustomerRelationDbService;
import com.crm.service.orderManager.CustomerProductOrderDbService;
import com.crm.service.returnMoney.ReturnMoneyExamineDbService;
import com.crm.system.service.csd.CsdMainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author renshaorong
 * @Date 2021/12/16 4:13 下午
 */
@Service
@Slf4j
public class CsdMainServiceImpl implements CsdMainService {

    @Autowired
    private CustomerContractDbService customerContractDbService;

    @Autowired
    private CustomerRelationDbService customerRelationDbService;

    @Autowired
    private ProductExchangeDbService productExchangeDbService;

    @Autowired
    private CustomerProductOrderDbService customerProductOrderDbService ;

    @Autowired
    private ReturnMoneyExamineDbService returnMoneyExamineDbService ;

    /**
     * 客服首页-合同未审核、关联未审核、兑换未审核、回款未审核、退款未审核数据
     * @return
     */
    @Override
    public JSONObject getBriefing() {
        JSONObject jsonObject = new JSONObject();
        //合同未审核
        jsonObject.put("cntractReview",customerContractDbService.getCustomerContractNum());

        //关联未审核
        jsonObject.put("customerRelation",customerRelationDbService.getCustomerRelationNum());

        //兑换未审核
        jsonObject.put("productExchange",productExchangeDbService.getProductExchangeNum());

        //回款未审核
        jsonObject.put("bankFlowExamine",returnMoneyExamineDbService.getReturnMoneyExamineNum());

        //退款未审核
        jsonObject.put("customerProductOrder",customerProductOrderDbService.getcustomerProductOrderNum());

        return jsonObject;
    }

    /**
     * 客服首页-合同趋势折线图数据
     * @param year
     * @return
     */
    @Override
    public Map<String, List<Map<String,Object>>> listCsdContractReport(Integer year){

        Map<String,List<Map<String,Object>>> resultList = new HashMap<>();

        //创建会员
        List<Map<String,Object>> create = customerContractDbService.getContractNumByCreate(year);
        resultList.put("create",create);

        //通过会员
        List<Map<String,Object>> pass = customerContractDbService.getContractNumByPass(year, 2);
        resultList.put("pass",pass);

        //未通过
        List<Map<String,Object>> fail = customerContractDbService.getContractNumByPass(year, 3);
        resultList.put("fail",fail);

        //生效
        List<Map<String,Object>> effect = customerContractDbService.getContractNumByEffect(year);
        resultList.put("effect",effect);
        return resultList;
    }
}
